import org.annoflow.filter.AuditFilter;
import org.annoflow.policy.Policy;
import org.annoflow.policy.boundry.SecureClassPolicy;
import org.annoflow.filter.Filter;
import org.annoflow.filter.auth.*;

import student.web.internal.SharedPersistenceMap;

@Policy(policy=SecureClassPolicy.class)
public class UserRegistry {
	private static SharedPersistenceMap<User> userMap = new SharedPersistenceMap<User>(User.class);

	@Filter(type=NewUserFilter.class)
	public static User createUser(String userName, String password) {
		if(userMap.get(userName) != null)
		{
			return null;
		}
		User newUser = new User(password);
		userMap.put(userName, newUser);
		return newUser;
	}

	public static User authenticateUser(String userName, String password) {
		User lookUp = userMap.get(userName);
		if (lookUp != null && lookUp.getPassword().equals(password))
			return lookUp;
		return null;
	}
	public static void updateUser(User user)
	{
		userMap.put(user.getName(), user);
	}

}
